package com.kobeliu.service.impl;

import com.kobeliu.base.BaseInfoProperties;
import com.kobeliu.mapper.SysParamsMapper;
import com.kobeliu.pojo.SysParams;
import com.kobeliu.pojo.vo.SysParamsVO;
import com.kobeliu.service.SysParamService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
public class SysParamServiceImpl extends BaseInfoProperties implements SysParamService {

    @Autowired
    private SysParamsMapper sysParamsMapper;

    @Transactional
    @Override
    public void modifyMaxResumeRefreshCounts(Integer maxCounts,Integer version) {

        SysParams params = new SysParams();
        params.setId(SYS_PARAMS_PK);
        params.setMaxResumeRefreshCounts(maxCounts);

        int num = sysParamsMapper.updateById(params);
        log.info("改变的行数：{}",num);
    }

    @Override
    public SysParamsVO params() {

        SysParamsVO vo = new SysParamsVO();

        SysParams sysParams = sysParamsMapper.selectById(SYS_PARAMS_PK);
        if(sysParams != null){
            vo.setMaxResumeRefreshCounts(sysParams.getMaxResumeRefreshCounts());
            vo.setVersion(0);
        }
        return vo;
    }
}
